<template>
  <div class="like">
    <van-nav-bar
    title="我的收藏"
    />
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        offset="10"
        :immediate-check="false"
        @load="onLoad"
      >
        <InterViewCard v-for="item in list" :key="item.id" :item="item"></InterViewCard>
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { getCollectOrLikeListApi } from '@/api/collect';
import InterViewCard from '@/components/InterViewCard.vue';
export default {
  name: 'TtLike',
  components: {
    InterViewCard
  },
  data() {
    return {
      list: [],
      finished: false,
      loading: false,
      refreshing: false,
      params: {
        optType: 1,
        pageSize: 10,
        page: 1
      }
    }
  },
  methods: {
    async onLoad() {
      this.params.page++
      await this.getData()
      this.loading = false
    },
    async onRefresh() {
      // 清空列表数据
      this.finished = false
      
      this.params.page = 1
      this.list = []
      await this.getData()
      this.refreshing = false
    },
    async getData() {
      const res = await getCollectOrLikeListApi(this.params)
      // console.log(res)
      this.list = this.params.page === 1 ? res.data.rows : [...this.list, ...res.data.rows]
      this.finished = this.params.page < res.data.total ? false : true
    }
  },
  created() {
    this.getData()
  }
}
</script>

<style lang="less" scoped>
 .van-list {
    padding-bottom: 50px;
  }
</style>